<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Title</title>
    <!--引入axios组件-->
    <script src="js/axios.js"></script>
    <script src="js/vue@3.3.4.global.js"></script>
</head>
<body>
    <div id="app">
        <button @click="getData">使用axios发送请求</button>
        <ul>
            <li v-for="product in productList" :key="product.id">
                --{{product.id}}--{{product.title}}--{{product.image}}-{{product.price}}
            </li>
        </ul>
    </div>
</body>
</html>
<script>
    //创建Vue的实例
    const app = Vue.createApp({
        data(){
            return {
                productList:[] //数组
            }
        },
        methods:{
            getData(){
                console.log("调用api-------")
                axios.get('http://localhost:8081/api/product/new').then(resp=>{
                    console.log(resp)
                    console.log('响应码：',resp.data.code);
                    console.log('数据：',resp.data.data);
                    //为model中的变量赋值
                    this.productList = resp.data.data;
                }).catch(err=>{
                    console.log(err)
                });
            }
        }
    })
    app.mount('#app');
</script>